/*
 * PConexion.java
 *
 * Created on 5 de septiembre de 2006, 08:48 AM
 */
package ig.formato.gui.app;

import ig.basic.util.IMetodosPantallas;
import ig.formato.basic.ManipulacionDatos;
import ig.formato.modelo.MParametros;
import ig.formato.util.IGFormatoException;
import ig.formato.util.OBJETOS;
import java.awt.Component;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

/**
 *
 * @author  jsanchez
 */
public class PParametros extends javax.swing.JPanel implements IMetodosPantallas {

    private ManipulacionDatos mpd;
    private MParametros modelo = null;
    private JFrame frame = null;

    /** Creates new form PConexion */
    public PParametros(JFrame frame) {
        initComponents();
        this.frame = frame;
        mpd = new ManipulacionDatos(true, false);
        //mpd.setConfimacioSalir(true,"Desea cerrar la ventana?");
        mpd.setPanelMetodosPantalla(this);
        mpd.setSize(600, 200);
        mpd.setResizable(false);
        mpd.setMaximizable(false);
        //mpd.setTitle("Configuracion de conexiones");
        modelo = new MParametros(this);
        combo.removeAllItems();
        combo.addItem("##0.00");
        combo.addItem("#,##0.00");
        combo.addItem("¤ #,##0.00");
        combo.addItem("0.0#E0");
        combo.addItem("#,##0.00 %");
        combo.addItem("dd/MM/yyyy");
        combo.addItem("MM/dd/yyyy");
        combo.addItem("yyyy/MM/dd");
        combo.addItem("MMMMM dd, yyyy");
        combo.addItem("hh 'o''clock' a, zzzz");
        combo.addItem("EEEEE dd MMMMM yyyy");
        combo.addItem("<NINGUNO>");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel8 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        Nombre = new javax.swing.JTextField();
        combo = new javax.swing.JComboBox();
        Btest = new javax.swing.JButton();

        jLabel8.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText(org.openide.util.NbBundle.getMessage(PParametros.class, "PParametros.jLabel8.text")); // NOI18N

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 10));
        jLabel1.setText(org.openide.util.NbBundle.getMessage(PParametros.class, "PParametros.jLabel1.text")); // NOI18N

        jLabel2.setFont(new java.awt.Font("Dialog", 0, 10));
        jLabel2.setText(org.openide.util.NbBundle.getMessage(PParametros.class, "PParametros.jLabel2.text")); // NOI18N

        Nombre.setFont(new java.awt.Font("Dialog", 0, 10));
        Nombre.setText(org.openide.util.NbBundle.getMessage(PParametros.class, "PParametros.Nombre.text")); // NOI18N
        Nombre.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        combo.setFont(new java.awt.Font("Dialog", 0, 10));

        Btest.setFont(new java.awt.Font("DejaVu Sans", 0, 11));
        Btest.setText(org.openide.util.NbBundle.getMessage(PParametros.class, "PParametros.Btest.text")); // NOI18N
        Btest.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        Btest.setOpaque(true);
        Btest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtestActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
                            .add(jLabel2))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(Nombre, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(Btest, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(combo, 0, 431, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel8)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(Nombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(Btest, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(combo))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void BtestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtestActionPerformed
        try {
            this.validar();
            Class.forName(this.Nombre.getText().trim());
            mpd.showMensajeSimple("La Clase se cargo sin problemas.\n"+this.Nombre.getText().trim());
        } catch (IGFormatoException ex) {
            mpd.showMensaje(ex);
        } catch (ClassNotFoundException ex) {            
            mpd.showMensaje(new IGFormatoException(ex,"No se pudo cargar el tipo descrito","Verifique que la calse existe, o que este bien escrita."));
        }
}//GEN-LAST:event_BtestActionPerformed
    
    public JInternalFrame getInternalFrame() {
        return mpd;
    }
    
    public void validar() throws ig.formato.util.IGFormatoException {
        if(this.Nombre.getText().trim().equals(""))
            throw new ig.formato.util.IGFormatoException("No se escribio un nombre","Escriba el tipo de dato.");
        
        if(this.combo.getSelectedItem()==null)
            throw new ig.formato.util.IGFormatoException("No se seleccion\u00F3 un tipo de formato","Seleccione el tipo de formato.");
        
        ((ig.formato.dto.ParametroDTO)modelo.getTO()).setNombre(this.Nombre.getText());
        ((ig.formato.dto.ParametroDTO)modelo.getTO()).setValor(this.combo.getSelectedItem().toString());
    }
    
    public void guardar() throws ig.formato.util.IGFormatoException {
        modelo.guardar();
        this.actualizar();
    }
    
    public void buscar() throws ig.formato.util.IGFormatoException, ig.formato.util.NinguDatoSeleccionadoException{
        DBusqueda dialog=new DBusqueda(this.getFrame(),this.modelo,modelo.buscar());
        dialog.setVisible(true);
        if(dialog.getOpcion().equals(OBJETOS.NO_SELECCION)){
            throw new ig.formato.util.NinguDatoSeleccionadoException();
        }else{
            this.actualizar();
        }
    }
    
    public void modificar() throws ig.formato.util.IGFormatoException {
        modelo.modificar();
    }
    
    public void nuevo() throws ig.formato.util.IGFormatoException {
        modelo.nuevo();
    }
    
    public void eliminar() throws ig.formato.util.IGFormatoException {
        modelo.eliminar();
    }
    
    public void salir() throws ig.formato.util.IGFormatoException {
        modelo.salir();
    }
    
    public void imprimir() throws ig.formato.util.IGFormatoException {
    }
    public Map getParametros() throws IGFormatoException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public ig.basic.util.IModelo getModelo() throws IGFormatoException {
        return this.modelo;
    }    
    public void limpiar() throws IGFormatoException {
    
    }
    
    public void cancelar() throws ig.formato.util.IGFormatoException {
        modelo.cancelar();
        this.actualizar();
    }
    
    public Component[] getControles() {
        return null;
    }
    
    public void setFrame(JFrame frame) {
        this.frame=frame;
    }
    
    public JFrame getFrame() {
        return frame;
    }
    
    public Object getTO() throws ig.formato.util.IGFormatoException {
        return null;
    }
    public void actualizar() throws IGFormatoException {
        this.Nombre.setText(((ig.formato.dto.ParametroDTO)modelo.getTO()).getNombre());
        this.combo.setSelectedItem(((ig.formato.dto.ParametroDTO)modelo.getTO()).getValor());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Btest;
    private javax.swing.JTextField Nombre;
    private javax.swing.JComboBox combo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel8;
    // End of variables declaration//GEN-END:variables
    
}
